package com.neu.servlet.klz;

import com.alibaba.fastjson.JSONObject;
import com.neu.service.klz.GoodDaoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryGoodServlet", urlPatterns = {"/QueryGoodServlet.do"})
public class QueryGoodServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       response.setCharacterEncoding("UTF-8");
        String g_id=request.getParameter("g_id");
        String g_name=request.getParameter("g_name");
        String g_now=request.getParameter("g_now");
        String g_num=request.getParameter("g_num");
        GoodDaoService goodDaoService=new GoodDaoService();
        List<Map<String,Object>> Glist=goodDaoService.dofindByGood();
        HttpSession session = request.getSession();
        session.setAttribute("Glist",Glist);
        String json=JSONObject.toJSONString(Glist);
        System.out.println(json);
        PrintWriter out=response.getWriter();
        out.print(json);
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
